// minix.js
export default {
  data () {
    return {

    }
  },
  mounted () {
  },
  methods: {
    testPhone (phoneNum) {
      let vm = this
      if (!(/^1[3456789]\d{9}$/.test(phoneNum))) {
        vm.$message('手机号有误，请重填')
        return false
      }
    },
    getDate (value) {
      var day1 = new Date()
      day1.setTime(day1.getTime() + value * 24 * 60 * 60 * 1000)
      return day1.getFullYear() + '-' + ((day1.getMonth() + 1) < 10 ? '0' + (day1.getMonth() + 1) : (day1.getMonth() + 1)) + '-' + (day1.getDate() < 10 ? '0' + day1.getDate() : day1.getDate())
    },
    isAndroid () {
      var u = navigator.userAgent
      var isAndroid = u.indexOf('Android') > -1 || u.indexOf('Adr') > -1
      if (isAndroid) {
        return true
      }
      return false
    },
        /* 智慧总仓操作显示屏参数规则：
           M F C P D 分别代表面料、辅料、裁片、成品、设备
           100001 箱 包
           100002 服 装
           100003 电 子
       参数规则：M100001 */
    codeFormat (code) {
      let type1, type2
      if (code) {
        switch (code.slice(0, 1)) {
          case 'M':
            type2 = '面料'
            break
          case 'F':
            type2 = code.slice(1, code.length) === '100003' ? '原料' : '辅料'
            break
          case 'C':
            type2 = '裁片'
            break
          case 'P':
            type2 = '成品'
            break
          case 'D':
            type2 = '设备'
            break
        }
        switch (code.slice(1, code.length)) {
          case '100001':
            type1 = '箱包'
            break
          case '100002':
            type1 = '服装'
            break
          case '100003':
            type1 = '电子'
            break
        }
      }
      return type1 + type2
    },
    warehouseDistinct () {
      let result = []
      if (localStorage.getItem('WarehouseFlnkID')) {
        var arr = JSON.parse(localStorage.getItem('WarehouseFlnkID'))
        arr.forEach(item => {
          if (result.indexOf(item.WarehouseFlnkID) <= -1 && item.WarehouseFlnkID !== '00000000-0000-0000-0000-000000000000' &&
            item.WarehouseFlnkID !== '') {
            result.push(item.WarehouseFlnkID)
          }
        })
      }
      return result.join(',')
    },
    warehouseFormat (type) {
      let result = '00000000-0000-0000-0000-000000000000'
      if (localStorage.getItem('WarehouseFlnkID')) {
        result = JSON.parse(localStorage.getItem('WarehouseFlnkID')).filter((item) => {
          return item.type === type
        })[0].WarehouseFlnkID
      }
      return result
    },
    getTreeFormatJson (_dataJson) {
      let vm = this
      var easyTreeFormatJson = []
      if (_dataJson != null && _dataJson.length > 0) {
            // 读取所有的-1 根节点
        var easyRootJson = _dataJson.filter(function (_eItem) { return _eItem.pid === '-1' })
        if (easyRootJson != null && easyRootJson.length > 0) {
          easyRootJson.forEach(function (_rOldItem, _rIndex) {
            var _rItem = _rOldItem
            var easyChildJson = _dataJson.filter(function (_cItem) { return _cItem.pid === _rItem.id })
            if (easyChildJson != null && easyChildJson.length > 0) {
              // _rItem.state = (_rItem.state != null && _rItem.state !== undefined ? _rItem.state : 'closed')
              _rItem.children = vm.getChildTreeJson(_dataJson, _rItem.id)
            }
            easyTreeFormatJson.push(_rItem)
          })
        }
      }
      return easyTreeFormatJson
    },
    getChildTreeJson (_dataJson, _ePid) {
      let vm = this
      var easyTreeFormatJson = []
      var easyChildJson = _dataJson.filter(function (_cItem) { return _cItem.pid === _ePid })
      if (easyChildJson != null && easyChildJson.length > 0) {
        easyChildJson.forEach(function (_rOldItem, _rIndex) {
          var _rItem = _rOldItem
          var easyChildJson1 = _dataJson.filter(function (_cItem) { return _cItem.pid === _rItem.id })
          if (easyChildJson1 != null && easyChildJson1.length > 0) {
            // _rItem.state = (_rItem.state != null && _rItem.state !== '' && _rItem.state !== undefined ? _rItem.state : 'closed')
            _rItem.children = vm.getChildTreeJson(_dataJson, _rItem.id)
          }
          easyTreeFormatJson.push(_rItem)
        })
      }
      return easyTreeFormatJson
    }
  }
}
